//
//  ViewController.m
//  XTBackRunningDemo
//
//  Created by mshi on 2022/1/20.
//

#import "ViewController.h"

@interface ViewController ()
@property (nonatomic,assign) int timeCount;
@property (nonatomic,strong) UILabel *timeLabel;
@property (nonatomic,strong) NSTimer *timer;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.timeCount = 0;
    [self initUI];
    [self timeDown];
    // Do any additional setup after loading the view.
}

- (void)initUI {
    UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(([UIScreen mainScreen].bounds.size.width-100)/2, 200, 100, 40)];
    timeLabel.backgroundColor = [UIColor clearColor];
    timeLabel.font = [UIFont boldSystemFontOfSize:24];
    timeLabel.textColor = [UIColor redColor];
    timeLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:timeLabel];
    
    self.timeLabel = timeLabel;
}

- (void)timeDown {
    __weak typeof(self) weakSelf = self;
    self.timer = [NSTimer scheduledTimerWithTimeInterval:1 repeats:YES block:^(NSTimer * _Nonnull timer) {
        __strong typeof(self) self = weakSelf;
        self.timeCount ++;
        self.timeLabel.text = [NSString stringWithFormat:@"%d",self.timeCount];
    }];
}


@end
